import CONSTANT from '@/common/constants.js';
import http from '@/common/http.js';
import util from '@/common/util.js';

export default {
  name: 'myClass',
  components: {},
  data () {
    return {
      studentId: '',
      studentName: '',
      oldClassId: '',
      siteId: '',
      applyId: '',
      keyWords: '',
      status: '',
      pageNo: 1,
      content: [],
      content: {}
    }
  },
  mounted () {
    var _this = this
    _this.siteId = window.sessionStorage.getItem('siteId')
    _this.studentId = window.sessionStorage.getItem('studentId')
    _this.studentName = window.sessionStorage.getItem('studentName')
    _this.applyId = this.$route.query.applyId
    _this.oldClassId = this.$route.query.oldClassId
    if (_this.studentName == '-1') {
      let params = '?siteId=' + _this.siteId + '&studentId=' + _this.studentId;
      http.get(CONSTANT.STUDENTVIEW + params, {
        siteId: this.siteId,
        studentId: this.studentId
      }, (res) => {
        _this.studentName = res.name
      })
    }
    _this.goList()
  },
  methods: {
    goRefund(applyId) {
      this.$router.push({path: '/refund',query:{applyId:applyId}})
    },
    goList () {
      var _this = this
      http.post(CONSTANT.SAMECLASS + '?applyId=' + _this.applyId + '&pageNo=' + _this.pageNo, {
      }, (res) => {
        for (var i = 0; i < res.length; i++) {
          let dateStr = util.dateFormat(res[i].beginDate,false)
          let endStr = util.dateFormat(res[i].endDate,false)
          res[i].beginDate = dateStr
          res[i].endDate = endStr
        }
        if (res.length > 0) {
          if (_this.pageNo == 1) {
            _this.content = res
          } else {
            _this.content = _this.content.concat(res)
          }
        } else {
          if (_this.pageNo > 1) {
            _this.pageNo--
          }
          alert('没有更多了!')
        }
      })
    },
    lookMore () {
      var _this = this
      _this.pageNo++
      _this.goList()
    },
    comeBack () {
      window.history.go(-1)
    },
    hb(classId,orgId) {
      let _this = this
      http.post(CONSTANT.CLAZZCHANGE, {
        userId: _this.studentId,
        orgId: orgId,
        oldClassId: _this.oldClassId,
        newClassId: classId
      }, (res) => {
        alert(JSON.stringify(res))
        this.$router.push({path: '/myClass'})
      })
    }
  }
}
